package com.thwj.project.app.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thwj.common.annotation.Log;
import com.thwj.common.enums.BusinessType;
import com.thwj.framework.web.domain.R;
import com.thwj.framework.web.service.TokenService;
import com.thwj.project.app.api.param.UserDiDiParam;
import com.thwj.project.app.api.vo.MessageTypeVo;
import com.thwj.project.app.api.vo.MessageVo;
import com.thwj.project.app.api.vo.UserDiDiVo;
import com.thwj.project.app.service.AppMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags="app用户消息")
@RestController
@RequestMapping("/app/message")
public class AppMessageController {


    @Autowired
    private AppMessageService appMessageService;
    @Autowired
    private TokenService tokenService;

    @ApiOperation(value = "读取未读消息个数",notes = "读取未读消息个数")
    @GetMapping("/getMessageUnReadCount")
    public R<Integer> getMessageUnReadCount() {
        Integer unReadCount = appMessageService.getMessageUnReadCount(tokenService.getLoginUser());
        return R.data(unReadCount);
    }
    @ApiOperation(value = "读取消息分类列表",notes = "读取消息分类列表 消息中心的消息统一收录进分类列表 然后通过列表读取具体的消息")
    @GetMapping("/getMessageTypeList")
    public R<List<MessageTypeVo>> getMessageTypeList() {
        List<MessageTypeVo> messageTypeList = appMessageService.getMessageTypeList(tokenService.getLoginUser());
        return R.data(messageTypeList);
    }

    @ApiOperation(value = "获取消息分页列表",notes = "只有系统消息和动态消息使用")
    @GetMapping("/getMessagePage")
    public R<Page<MessageVo>> getMessagePage(Page page, @RequestParam Integer messageType) {
        Page<MessageVo> messageVoPage = appMessageService.getMessagePage(page,messageType, tokenService.getLoginUser());
        return R.data(messageVoPage);
    }


    @ApiOperation(value = "获取DIDI申请分页列表",notes = "只有didi消息使用")
    @GetMapping("/getUserDiDiVoPage")
    public R<Page<UserDiDiVo>> getUserDiDiVoPage(Page page) {
        Page<UserDiDiVo> userDiDiVoPage = appMessageService.getUserDiDiVoPage(page, tokenService.getLoginUser());
        return R.data(userDiDiVoPage);
    }



    @Log(title = "用户DIDI申请", businessType = BusinessType.INSERT)
    @ApiOperation(value = "用户发送DiDi申请",notes = "该操作放置在用户主页和动态列表等场景")
    @PostMapping("commitUserDiDi")
    public R<String> commitUserDiDi(@RequestBody UserDiDiParam userDiDiParam) {
        appMessageService.commitUserDiDi(userDiDiParam, tokenService.getLoginUser());
        return R.data("申请已发送，等待对方同意");
    }


    @Log(title = "确认DIDI通过", businessType = BusinessType.INSERT)
    @ApiOperation(value = "确认用户DIDI申请通过",notes = "确认用户DIDI申请通过")
    @PostMapping("confirmUserDiDi")
    public R<String> confirmUserDiDi(@RequestBody UserDiDiParam userDiDiParam) {
        appMessageService.confirmUserDiDi(userDiDiParam.getUserDiDiId(), tokenService.getLoginUser());
        return R.data("确认DIDI通过");
    }


    @Log(title = "确认DIDI不通过", businessType = BusinessType.INSERT)
    @ApiOperation(value = "不同意用户DIDI申请",notes = "不同意用户DIDI申请")
    @PostMapping("refuseUserDiDi")
    public R<String> refuseUserDiDi(@RequestBody UserDiDiParam userDiDiParam) {
        appMessageService.refuseUserDiDi(userDiDiParam.getUserDiDiId(), tokenService.getLoginUser());
        return R.data("确认DIDI不通过");
    }

}
